var viewer = new Cesium.Viewer("cesiumViewer", {
    animation: false,
    fullscreenButton: false,
    timeline: false,
    projectionPicker: true,
    mapProjection: new Cesium.WebMercatorProjection(),
});


var scene = viewer.scene;

// scene.completeMorphOnUserInput = false;

// scene.debugCommandFilter = function(command) {
//     return true;
// };

//scene.debugShowCommands = true;
scene.debugShowFramesPerSecond = true;

scene.requestRenderMode = true;

scene.scene3DOnly = true;

//scene.screenSpaceCameraController.enableCollisionDetection = false;
//scene.screenSpaceCameraController.enableRotate = false;


// scene.postRender.addEventListener(function(){
//     console.log("postRender");
// });

scene.morphComplete.addEventListener(function () {
    console.log("morphComplete");
});


var entitys = new Array();

for (var i = 0; i < 2; i++) {

    var et = viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(113 + 2 * i, 36, 0.0),
        cylinder: {
            length: 200000.0,
            topRadius: 150000.0,
            bottomRadius: 150000.0,
            outline: true,
            outlineColor: Cesium.Color.WHITE,
            outlineWidth: 4,
            material: Cesium.Color.fromRandom({
                alpha: 1.0
            })
        }
    });

    entitys.push(et);
}

function testFlyTo() {
    viewer.flyTo(entitys[0]);

}

function testZoomTo() {
    viewer.zoomTo(entitys[0]);
}

function morphTo2D() {
    viewer.scene.morphToColumbusView(5);
}

var handle = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handle.setInputAction(function (evt) {

        var picres = viewer.scene.pickPosition(evt.position, new Cesium.Cartesian3());

        var ellipsoid = viewer.scene.globe.ellipsoid;
        var cartographic = ellipsoid.cartesianToCartographic(picres);
        var lat = Cesium.Math.toDegrees(cartographic.latitude);
        var lng = Cesium.Math.toDegrees(cartographic.longitude);
        var msg1 = '经度：' + cartographic.longitude + ', 纬度：' + cartographic.longitude;
        var msg = '经度：' + lng + ', 纬度：' + lat;
        //alert(msg);
        console.log(msg1);
        console.log(msg);
    },
    Cesium.ScreenSpaceEventType.LEFT_CLICK);
